import axios from 'axios';
import mpAdapter from "axios-miniprogram-adapter"
axios.defaults.adapter = mpAdapter;

// 创建 axios 实例
const service = axios.create({
    baseURL: 'http://127.0.0.1:3011',
    timeout: 10000 // 请求超时时间
});

// 请求拦截器
service.interceptors.request.use(
    config => {
        let token = uni.getStorageSync('token');
        if (token) {

        } else {
            token = '';
        }
        config.headers['Authorization'] = token;
        return config;
    },
    error => {
        // 请求错误处理
        return Promise.reject(error);
    }
);

// 响应拦截器
service.interceptors.response.use(
    response => {
        if (response.status === 200) {
            return response;
        } else {
            console.log("错误了", response);
            return Promise.reject(error);
        }
    },
);

export default service;